import com.sibirjak.asdpc.button.Button;

import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

static private var TITLE:String = 'title';

private var _callbacks:Object = {};

public function initTitle( $btnStartClickCallback:Function ):void{
	addScene( TITLE );
	addText( getScene( TITLE ), TITLE, 'My Bejeweled' );
	addButton( getScene( TITLE ), 'btnStart', 'Start', 100, 22, $btnStartClickCallback );
}
public function showTitle():void{
	getScene( TITLE ).visible = true;
}
public function hideTitle():void{
	getScene( TITLE ).visible = false;
}
private function addScene( $name:String ):void{
	var scene:Sprite;
	
	scene = new Sprite;
	scene.name = $name;
	addChild( scene );
}
private function getScene( $name:String ):DisplayObjectContainer{
	return getChildByName( $name ) as DisplayObjectContainer;
}
private function addText( $target:DisplayObjectContainer, $name:String, $text:String ):void{
	var text:TextField;
	
	text = new TextField;
	text.name = $name;
	text.defaultTextFormat = new TextFormat( 'nanum', 24, 0x0070ba );
	text.embedFonts = true;
	text.selectable = false;
	text.autoSize = TextFieldAutoSize.CENTER;
	text.x = stage.stageWidth*.5 - text.width*.5;
	text.y = stage.stageHeight*.5 - text.height*.5;
	text.text = $text;
	$target.addChild( text );
}
private function addButton( $target:DisplayObjectContainer, $name:String, $label:String, $width:Number, $height:Number, $callback:Function ):void{
	var button:Button;
	
	button = new Button;
	button.name = $name;
	button.addEventListener( MouseEvent.CLICK, function( $e:MouseEvent ):void{
		$callback();
	} );
	button.label = $label;
	button.setSize( $width, $height );
	button.x = stage.stageWidth*.5 - button.width*.5;
	button.y = stage.stageHeight - button.height - 50;
	$target.addChild( button );
}
